# -*-* encoding:UTF-8 -*-
# author            : mengy
# date              : 2018/12/14
# python-version    : Python 3.7.0
# description       : 登录时进入的初始房间

from com.python.demo.mutil_chatting_room.entities.Room import Room


class LoginRoom(Room):
    "处理登录用户"

    def add(self, session):
        "用户登录成功的响应"
        Room.add(self, session)
        session.push(b'Connect Successful')

    def do_login(self, session, line):
        "用户登录逻辑"
        name = line.strip()
        if not name:
            session.push(b'Username is empty!')
        elif name in self.server.users:
            session.push(b'Username is exists')
        else:
            session.name = name
            session.enter(self.server.main_room)
